﻿// EstimateDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "学生管理系统MFC.h"
#include "EstimateDlg.h"
#include "afxdialogex.h"


// CEstimateDlg 对话框

IMPLEMENT_DYNAMIC(CEstimateDlg, CDialogEx)

CEstimateDlg::CEstimateDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_ESTIMATEDLG, pParent)
{

}

CEstimateDlg::~CEstimateDlg()
{
}

void CEstimateDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO1, m_combobox1);
	DDX_Control(pDX, IDC_COMBO2, m_combobox2);
	DDX_Control(pDX, IDC_LIST1, m_list);
}


BEGIN_MESSAGE_MAP(CEstimateDlg, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON1, &CEstimateDlg::OnBnClickedButton1)
	ON_WM_SHOWWINDOW()
END_MESSAGE_MAP()


// CEstimateDlg 消息处理程序


BOOL CEstimateDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	m_combobox1.SetCurSel(0);
	m_combobox2.SetCurSel(0);
	CRect rect;
	// 获取编程语言列表视图控件的位置和大小   
	m_list.GetClientRect(&rect);
	// 为列表视图控件添加全行选中和栅格风格   
	m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
	m_list.InsertColumn(0, _T("课程名称"), LVCFMT_CENTER, rect.Width() / 3, 0);
	m_list.InsertColumn(1, _T("课程类别"), LVCFMT_CENTER, rect.Width() / 3, 0);
	m_list.InsertColumn(2, _T("学年"), LVCFMT_CENTER, rect.Width() / 3, 0);
	m_list.InsertColumn(3, _T("学期"), LVCFMT_CENTER, rect.Width() / 3, 0);
	m_list.InsertColumn(4, _T("授课老师"), LVCFMT_CENTER, rect.Width() / 3, 0);
	m_list.InsertColumn(5, _T("评价起止周时间	"), LVCFMT_CENTER, rect.Width() / 3, 0);
	// TODO:  在此添加额外的初始化

	return TRUE;  // return TRUE unless you set the focus to a control
				  // 异常: OCX 属性页应返回 FALSE
}

void CEstimateDlg::Query()
{
	CString sql, 学年, 学期;
	((CComboBox*)GetDlgItem(IDC_COMBO1))->GetWindowText(学年);
	学年 = 学年.Mid(5, 4);
	((CComboBox*)GetDlgItem(IDC_COMBO2))->GetWindowText(学期);
	sql = _T("SELECT DISTINCT 成绩.[课头号],[课程名],[课程类型],教师.[姓名],课程.[年级],课程.[学期],[评价起止周时间] FROM 教师,课程,学生,成绩 WHERE 教师.工号=课程.教师 AND dbo.[学生].[学号] = ") + m_username + _T(" AND dbo.[学生].[学号] = dbo.[成绩].[学号] AND dbo.[课程].[课头号] = dbo.[成绩].[课头号] AND dbo.[成绩].[年级] = ") + 学年 + _T(" AND dbo.[成绩].[学期] = '") + 学期 + _T("'");
	::CoInitialize(NULL);
	g_pDB->Initialize(ConnectionAddress, ConnectionDB, ConnectionUser, ConnectionPassword);
	CSqlStatement *stmt = g_pDB->ExecuteSQL(sql);
	while (stmt != NULL)
	{
		if (stmt->NextRow() == NULL)
		{
			break;
		}
		int nRow = m_list.InsertItem(0, stmt->ValueString(_T("课头号")));//插入行
		m_list.SetItemText(nRow, 1, stmt->ValueString(_T("课程名")));//设置数据
		m_list.SetItemText(nRow, 2, stmt->ValueString(_T("课程类型")));//设置数据
		m_list.SetItemText(nRow, 3, stmt->ValueString(_T("姓名")));//设置数据
		m_list.SetItemText(nRow, 4, stmt->ValueString(_T("年级")));//设置数据
		m_list.SetItemText(nRow, 5, stmt->ValueString(_T("学期")));//设置数据
		m_list.SetItemText(nRow, 6, stmt->ValueString(_T("评价起止周时间")));//设置数据
	}
	delete stmt;
	::CoUninitialize();
}

void CEstimateDlg::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	Query();
}


void CEstimateDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
	CDialogEx::OnShowWindow(bShow, nStatus);
	if (bShow == true)
		Query();
	// TODO: 在此处添加消息处理程序代码
}
void CEstimateDlg::OnOK()
{

}